<template>
    <div class="table-page">
        <div class="table-search-box" @keyup.enter="search()">
            <div class="search-item">
                <label>处理状态：</label>
                <div class="table-query-input">
                    <el-select
                        v-model="queryData.status"
                        filterable
                        clearable
                        placeholder="状态"
                        class="address-select"
                    >
                        <el-option
                            v-for="item in feedbackStas"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="search-item">
                <el-button
                    type="primary"
                    icon="el-icon-search"
                    :loading="tableLoading"
                    @click="clickSearch()"
                    >搜索
                </el-button>
            </div>
            <div class="search-item">
                <el-button
                    icon="el-icon-refresh"
                    :loading="tableLoading"
                    @click="resetSearch()"
                    >重置
                </el-button>
            </div>
        </div>
        <div class="table-operation-box">
            <el-button
                style="margin-bottom: 2em"
                type="success"
                :disabled="selectDisable"
                @click="changeStatus()"
                >批量处理
            </el-button>
            <el-button
                type="danger"
                style="margin-bottom: 2em"
                :disabled="selectDisable"
                @click="
                    tableDelete(
                        '/user/cu/feedback/deleted-list',
                        {
                            ids: tableSelect
                        },
                        true
                    )
                "
                >批量删除
            </el-button>
        </div>
        <div class="table-data-box">
            <el-table
                ref="table"
                v-loading="tableLoading"
                :data="tableData"
                border
                style="width: 100%;min-height:40em"
                row-key="id"
                @selection-change="tableSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center">
                </el-table-column>

                <el-table-column
                    prop="name"
                    label="提出人"
                    width="120"
                ></el-table-column>
                <el-table-column
                    prop="contact"
                    label="联系方式"
                    width="120"
                ></el-table-column>
                <el-table-column prop="status" label="处理状态" width="120">
                    <template slot-scope="scope">
                        <k-tag
                            :tag="feedbackStatus[scope.row.status]"
                            :text="true"
                        ></k-tag>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="content"
                    label="反馈意见"
                    min-width="200"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="remark"
                    label="处理备注"
                    min-width="200"
                    show-overflow-tooltip
                ></el-table-column>

                <el-table-column
                    prop="createdTime"
                    label="创建时间"
                    width="180"
                >
                </el-table-column>
                <el-table-column
                    label="操作"
                    width="400"
                    align="center"
                    fixed="right"
                >
                    <template slot-scope="scope">
                        <el-button
                            v-if="!scope.row.edit"
                            type="text"
                            icon="el-icon-picture-outline"
                            size="mini"
                            :loading="scope.row.opLoading"
                            @click="clickSimpleEdit(scope.row, '详情')"
                            >详情
                        </el-button>
                        <el-button
                            v-if="!scope.row.edit"
                            class="danger"
                            type="text"
                            icon="el-icon-delete"
                            size="mini"
                            :loading="scope.row.opLoading"
                            @click="
                                tableDelete(
                                    '/user/cu/feedback/delete',
                                    {
                                        id: scope.row.id
                                    },
                                    true
                                )
                            "
                            >删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div v-if="pageData.total" class="xy-between table-page-box">
            <el-pagination
                background
                :current-page.sync="pageData.currentPage"
                :page-sizes="pageData.pageSizes"
                :page-size.sync="pageData.pageSize"
                layout="total,  prev, pager, next, sizes, jumper"
                :total="pageData.total"
            >
            </el-pagination>
        </div>

        <el-dialog
            :title="dialogFormTitle"
            :visible.sync="dialogFormVisible"
            :before-close="dialogClose"
            width="60%"
        >
            <el-form
                ref="dataForm"
                :model="dataForm"
                label-width="8em"
                :rules="dataFormRule"
                class="table-edit-from border-form"
            >
                <el-form-item label="意见反馈" prop="content">
                    <!--                    <tinymce  v-if="dialogFormVisible" v-model="dataForm.content" width="95%"/>-->
                    <el-input
                        v-model="dataForm.content"
                        type="textarea"
                        :rows="6"
                        style="width: 700px;max-width:50em"
                    ></el-input>
                </el-form-item>
                <el-form-item label="处理备注" prop="remark">
                    <!--                    <tinymce  v-if="dialogFormVisible" v-model="dataForm.remark" width="95%"/>-->
                    <el-input
                        v-model="dataForm.remark"
                        type="textarea"
                        :rows="6"
                        style="width: 700px;max-width:50em"
                    ></el-input>
                </el-form-item>
                <el-form-item label="处理状态" prop="status">
                    <el-select v-model="dataForm.status" placeholder="请选择">
                        <el-option
                            v-for="item in feedbackStas"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button :loading="submitFlag" @click="dialogClose"
                    >取 消</el-button
                >
                <el-button
                    :loading="submitFlag"
                    type="primary"
                    @click="formDataSave('/user/cu/feedback/update')"
                    >保 存</el-button
                >
            </span>
        </el-dialog>

        <el-dialog
            :title="dialogFormTitle"
            :visible.sync="feedbackVisible"
            :before-close="dialogClose"
            width="60%"
        >
            <el-form
                ref="dataForm"
                :model="updateFrom"
                label-width="8em"
                class="table-edit-from border-form"
            >
                <el-form-item label="处理备注" prop="remark">
                    <el-input
                        v-model="updateFrom.remark"
                        type="textarea"
                        :rows="6"
                        style="width: 700px;max-width:50em"
                    ></el-input>
                </el-form-item>
                <el-form-item label="处理状态" prop="status">
                    <el-select v-model="updateFrom.status" placeholder="请选择">
                        <el-option
                            v-for="item in feedbackStas"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button :loading="submitFlag" @click="dialogClose"
                    >取 消</el-button
                >
                <el-button
                    :loading="submitFlag"
                    type="primary"
                    @click="feedbackSave()"
                    >保 存</el-button
                >
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { TablePage } from "@/layout/mixin/iVue.js";
import { mapState } from "vuex";
import { get, put, post } from "@/api/request";
import Tinymce from "@/components/Tinymce";

export default {
    name: "FeedbackList",
    components: { Tinymce },
    mixins: [TablePage],
    data() {
        return {
            feedbackVisible: false,
            updateFrom: {},
            queryData: {
                type: 0,
                name: "",
                orders: [
                    {
                        column: "status",
                        asc: true
                    },
                    {
                        column: "created_time",
                        asc: false
                    }
                ]
            },
            feedbackStas: [
                { value: "undo", label: "未处理" },
                { value: "laydo", label: "稍后处理" },
                { value: "hasdo", label: "已处理" },
                { value: "notdo", label: "无须处理" }
            ]
        };
    },
    computed: {
        ...mapState({
            feedbackStatus: state => state.status.FeedbackStatus
        })
    },
    watch: {},
    created() {},
    mounted() {},
    methods: {
        search(queryData) {
            this.loadTable("/user/cu/feedback/page", queryData);
        },

        changeStatus() {
            this.feedbackVisible = true;
        },
        feedbackSave() {
            console.log("???", this.tableSelect);
            this.updateFrom.ids = this.tableSelect;
            put(`/user/cu/feedback/batch-update`, this.updateFrom).then();
            this.feedbackVisible = false;
            this.search();
        }
    }
};
</script>

<style lang="scss" scoped>
.school-logo {
    .logo-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 108px;
        height: 108px;
        line-height: 108px;
        text-align: center;
    }

    .logo-img {
        width: 108px;
        height: 108px;
        display: block;
    }
}

.table-edit-from {
    .address-select {
        width: 8em;
        margin-right: 2em;
    }
}
</style>
<style>
.school-logo .logo-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.school-logo .logo-uploader .el-upload:hover {
    border-color: #409eff;
}
</style>
